/**
 * 
 */
package com.kathez.dao;

import java.util.List;

import com.kathez.entity.BusinessOperable;
import com.kathez.entity.KathezEntity;
import com.kathez.exceptions.KathezRuntimeException;

/**
 * @author Balaji T
 *
 */
public final class DAODeleteResultImpl extends AbstractDAODeleteResult {

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#getDeleteCount()
	 */
	@Override
	public int getDeleteCount() {
		return this.deleteCount;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#getDeleteErrCode()
	 */
	@Override
	public String getDeleteErrCode() {
		return this.deleteErrCode;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#getDeleteErrMsg()
	 */
	@Override
	public String getDeleteErrMsg() {
		return this.deleteErrMsg;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#getDeletedObject()
	 */
	@Override
	public BusinessOperable getDeletedObject() {
		return this.deletedObject;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#getDeletedObjectList()
	 */
	@Override
	public List<KathezEntity> getDeletedObjectList() {
		return this.deletedObjectList;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAODeleteResult#isDeleteSuccess()
	 */
	@Override
	public boolean isDeleteSuccess() {
		return this.deleteSuccess;
	}
	
	private int deleteCount;
	private String deleteErrCode;
	private String deleteErrMsg;
	private BusinessOperable deletedObject;
	private List<KathezEntity> deletedObjectList;
	private boolean deleteSuccess;
	private boolean overrideSuccesFlag;
	/**
	 * @param deleteCount the deleteCount to set
	 */
	private void setDeleteCount(int deleteCount) {
		this.deleteCount = deleteCount;
	}

	/**
	 * @param deleteErrCode the deleteErrCode to set
	 */
	public void setDeleteErrCode(String deleteErrCode) {
		this.deleteErrCode = deleteErrCode;
	}

	/**
	 * @param deleteErrMsg the deleteErrMsg to set
	 */
	public void setDeleteErrMsg(String deleteErrMsg) {
		this.deleteErrMsg = deleteErrMsg;
	}

	/**
	 * @param deletedObject the deletedObject to set
	 */
	public void setDeletedObject(BusinessOperable deletedObject) {
		if(deletedObject != null){
			if(this.deletedObjectList != null)
				throw new KathezRuntimeException("The Result already set for this object. The existing result is List of deleted objects");
			this.deletedObject = deletedObject;
			setDeleteCount(1);
			if(overrideSuccesFlag && !this.deleteSuccess)
				this.deleteSuccess = false;
			else
				this.deleteSuccess = true;
		}
		this.overrideSuccesFlag = false;
	}

	/**
	 * @param deletedObjectList the deletedObjectList to set
	 */
	public void setDeletedObjectList(List<KathezEntity> deletedObjectList) {
		if(deletedObjectList != null){
			if(this.deletedObject != null)
				throw new KathezRuntimeException("The Result already set for this object. The existing result is Single deleted object");
			this.deletedObjectList = deletedObjectList;
			setDeleteCount(deletedObjectList.size());
			if(overrideSuccesFlag && !this.deleteSuccess)
				this.deleteSuccess = false;
			else
				this.deleteSuccess = true;
		}
		this.overrideSuccesFlag = false;
	}

	/**
	 * @param deleteSuccess the deleteSuccess to set
	 */
	public void setDeleteSuccess(boolean deleteSuccess) {
		this.overrideSuccesFlag = true;
		this.deleteSuccess = deleteSuccess;
	}
	
}
